/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import model.MaterialDirection;
import draw.ColorSet;
import exceptions.*;
import model.Epoxy;
import model.Fiber;
import model.Lamel;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Memet
 */
public class AddLayer extends javax.swing.JFrame {

    private Fiber f;
    private Epoxy e;
    private double vf;
    private Color fiberColor;
    private Color epoxyColor;
    private MaterialDirection soort;
    /**
     * Creates new form AddLayer
     */
    public AddLayer() {
        initComponents();
        
        f = null;
        e = null;
        vf = 0.5;
        soort = MaterialDirection.UNIDIRECTIONAAL;
        rootPane.getContentPane().setBackground(Color.decode("#FFFFFF"));
        fiberColor = Color.red;
        epoxyColor = Color.white;
        /* todo refactor
        txtNaam.setText("Material" + Global.data.geefNieuweMaterialNaam());
        txtNaamPre.setText("Material" + Global.data.geefNieuweMaterialNaam());
        */
        updateForm();
        if((cbEpoxy.getComponents().length != 0) && (cbFibers.getComponents().length != 0))
        {
            e = (Epoxy) cbEpoxy.getItemAt(0);
            f = (Fiber) cbFibers.getItemAt(0);
        }
        updateForm();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        txtVf = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cbType = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btnFiberColor = new javax.swing.JButton();
        btnEpoxyColor = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtFabrikant = new javax.swing.JTextField();
        examp = new draw.pnlExample();
        jLabel2 = new javax.swing.JLabel();
        txtNaam = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtDikte = new javax.swing.JTextField();
        btnAddMaterial = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        cbFibers = new components.SteppedComboBox();
        cbEpoxy = new components.SteppedComboBox();
        jPanel2 = new javax.swing.JPanel();
        cbTypePre = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        txtDiktePre = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtNaamPre = new javax.swing.JTextField();
        txtFabrikantPre = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        btnAddMaterialPre = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        btnFiberColorPre = new javax.swing.JButton();
        btnEpoxyColorPre = new javax.swing.JButton();
        examp1 = new draw.pnlExample();
        jLabel12 = new javax.swing.JLabel();
        txtEl = new javax.swing.JTextField();
        txtEt = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtNult = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtRho = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        txtGlt = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtAlpha1 = new javax.swing.JTextField();
        txtAlpha2 = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTabbedPane1.setBackground(new java.awt.Color(255, 255, 255));
        jTabbedPane1.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        txtVf.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtVf.setText("0");
        txtVf.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtVfFocusLost(evt);
            }
        });


        jLabel1.setText("Fiber volume fraction");

        cbType.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        cbType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "UD", "-45° / + 45°", "0° / 90°" }));
        cbType.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbTypePopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
        });


        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jLabel4.setText("Fiber plot color");

        jLabel5.setText("Epoxy plot color");

        btnFiberColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFiberColorActionPerformed(evt);
            }
        });

        btnEpoxyColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEpoxyColorActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Manufacturer");

        txtFabrikant.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        examp.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 153, 0), 1, true));

        javax.swing.GroupLayout exampLayout = new javax.swing.GroupLayout(examp);
        examp.setLayout(exampLayout);
        exampLayout.setHorizontalGroup(
            exampLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 48, Short.MAX_VALUE)
        );
        exampLayout.setVerticalGroup(
            exampLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 18, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                                    .addComponent(jLabel5))
                                .addGap(72, 72, 72)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(btnFiberColor, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnEpoxyColor, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(txtFabrikant, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(examp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(examp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(btnFiberColor, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(btnEpoxyColor, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtFabrikant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );

        jLabel2.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Name");

        txtNaam.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtNaam.setText("Material01");

        jLabel6.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Thickness [mm]");

        txtDikte.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtDikte.setText("1");

        btnAddMaterial.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        btnAddMaterial.setText("Add Material");
        btnAddMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddMaterialActionPerformed(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        jLabel18.setText("Fiber");

        jLabel19.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        jLabel19.setText("Epoxy");

        cbFibers.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbFibers.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbFibersPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
        });
        cbFibers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbFibersActionPerformed(evt);
            }
        });

        cbEpoxy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbEpoxy.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbEpoxyPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAddMaterial, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNaam, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(cbType, 0, 105, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(txtDikte, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtVf, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbEpoxy, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
                            .addComponent(cbFibers, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cbFibers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbEpoxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtVf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDikte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtNaam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnAddMaterial)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Normal Material", jPanel1);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        cbTypePre.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        cbTypePre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "UD", "-45° / + 45°", "0° / 90°" }));
        cbTypePre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTypePreActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Thickness [mm]");

        txtDiktePre.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtDiktePre.setText("1");

        jLabel8.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Name");

        txtNaamPre.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtNaamPre.setText("Material01");

        txtFabrikantPre.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel9.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("Manufacturer");

        btnAddMaterialPre.setFont(new java.awt.Font("Rockwell", 1, 11)); // NOI18N
        btnAddMaterialPre.setText("Add Material");
        btnAddMaterialPre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddMaterialPreActionPerformed(evt);
            }
        });

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jLabel10.setText("Fiber plot color");

        jLabel11.setText("Epoxy plot color");

        btnFiberColorPre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFiberColorPreActionPerformed(evt);
            }
        });

        btnEpoxyColorPre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEpoxyColorPreActionPerformed(evt);
            }
        });

        examp1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 153, 0), 1, true));

        javax.swing.GroupLayout examp1Layout = new javax.swing.GroupLayout(examp1);
        examp1.setLayout(examp1Layout);
        examp1Layout.setHorizontalGroup(
            examp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 48, Short.MAX_VALUE)
        );
        examp1Layout.setVerticalGroup(
            examp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 18, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(72, 72, 72)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnFiberColorPre, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnEpoxyColorPre, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(examp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(examp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel10)
                    .addComponent(btnFiberColorPre, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addComponent(btnEpoxyColorPre, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(68, 68, 68))
        );

        jLabel12.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel12.setText("El [GPa]");

        txtEl.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtEl.setText("0");

        txtEt.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtEt.setText("0");

        jLabel13.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("Et [GPa]");

        txtNult.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtNult.setText("0");

        jLabel14.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel14.setText("vlt");

        txtRho.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtRho.setText("0");


        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("<html>ρ [Kg/m<sup>3</sup>]</html>");

        jLabel17.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel17.setText("Glt [GPa]");

        txtGlt.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtGlt.setText("0");

        jLabel16.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setText("<html>αl [°C<sup>-1</sup>]</html>");

        txtAlpha1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtAlpha1.setText("0");

        txtAlpha2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtAlpha2.setText("0");

        jLabel20.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel20.setText("<html>αt [°C<sup>-1</sup>]</html>");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtEl)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
                            .addComponent(txtEt, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtNult, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtGlt, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtAlpha1)
                            .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel20)
                            .addComponent(txtAlpha2, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbTypePre, 0, 107, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                            .addComponent(txtDiktePre, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                            .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                            .addComponent(txtRho, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtFabrikantPre)
                            .addComponent(txtNaamPre)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(btnAddMaterialPre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel12)
                                .addComponent(jLabel13))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel14)
                                .addComponent(jLabel17)
                                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(5, 5, 5)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtEt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtGlt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtAlpha1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(txtAlpha2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel8))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtRho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbTypePre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNaamPre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDiktePre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFabrikantPre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAddMaterialPre)
                .addGap(62, 62, 62))
        );

        jTabbedPane1.addTab("Prepreg", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtVfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtVfFocusLost
        double val = Double.parseDouble(txtVf.getText());
        if (val < 0.0) {
            vf = 0;
        } else if (val > 1.0) {
            vf = 1;
        } else {
            vf = val;
        }
        updateForm();
    }

    private void cbTypePopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbTypePopupMenuWillBecomeInvisible
        
        if (cbType.getSelectedIndex() == 0) {
            soort = MaterialDirection.UNIDIRECTIONAAL;
            cbTypePre.setSelectedIndex(0);
        } else if (cbType.getSelectedIndex() == 1) {
            soort = MaterialDirection.MINVIJFENVEERTIGVIJFENVEERTIG;
            cbTypePre.setSelectedIndex(1);
        }
        else {
            soort = MaterialDirection.NULNEGENTIG;
            cbTypePre.setSelectedIndex(2);
        }

        updateForm();
    }//GEN-LAST:event_cbTypePopupMenuWillBecomeInvisible

    private void btnFiberColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFiberColorActionPerformed
        JColorChooser cc = new JColorChooser();
        cc.setPreviewPanel(new JPanel());
        cc.repaint();
        Color kleurtje = cc.showDialog(rootPane, "Choose a Color", Color.red);
        if (kleurtje != null) {
            fiberColor = kleurtje;
        }
        btnFiberColor.setBackground(fiberColor);
        updateForm();
    }//GEN-LAST:event_btnFiberColorActionPerformed

    private void btnEpoxyColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEpoxyColorActionPerformed
        JColorChooser cc = new JColorChooser();
        cc.setPreviewPanel(new JPanel());
        cc.repaint();
        Color kleurtje = cc.showDialog(rootPane, "Choose a Color", Color.red);
        if (kleurtje != null) {
            epoxyColor = kleurtje;
        }
        btnEpoxyColor.setBackground(epoxyColor);
        updateForm();
    }//GEN-LAST:event_btnEpoxyColorActionPerformed

    private void btnAddMaterialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddMaterialActionPerformed
        updateForm();
        try {
            soort = MaterialDirection.NULNEGENTIG;
            if (cbType.getSelectedIndex() == 0) {
                soort = MaterialDirection.UNIDIRECTIONAAL;
            } else if (cbType.getSelectedIndex() == 1) {
                soort = MaterialDirection.MINVIJFENVEERTIGVIJFENVEERTIG;
            }
            if (txtNaam.getText().equalsIgnoreCase("")) {
                throw new NoNameGivenException();
            }
            //Global.data.addMateriaal(new Lamel(f, e, vf, txtNaam.getText(), EtBerekeningsMethode.Halpin_Tsaj_Hahn, soort, Double.parseDouble(txtDikte.getText()), new ColorSet(epoxyColor, fiberColor), txtFabrikant.getText()));
            Lamel lamel = new Lamel(f, e, vf);
            lamel.setName(txtNaam.getText());
            lamel.setType(soort);
            lamel.setColorSet(new ColorSet(fiberColor, epoxyColor));
            /* todo refactor
            Global.data.addLamel(lamel);
            
            if (txtNaam.getText().equals("Material" + Global.data.geefNieuweMaterialNaam())) {
                Global.data.gebruikNieuweMaterialNaam();
            }
            Global.menu.refreshScreens();
            */
            this.dispose();
        /*} catch (NameAlreadyExistsException ex) {
            JOptionPane.showMessageDialog(rootPane, "The name you used already exists");*/
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(rootPane, "One of the values you entered is not valid");
        } catch (NoNameGivenException ex) {
            JOptionPane.showMessageDialog(rootPane, "Please enter a name for the material");
        }catch (ValueNotBetweenZeroAndOneException ex) {
            Logger.getLogger(AddLayer.class.getName()).log(Level.SEVERE, null, ex);
        }
        //updateForm();
    }//GEN-LAST:event_btnAddMaterialActionPerformed

    private void cbFibersPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbFibersPopupMenuWillBecomeInvisible
        if (cbFibers.getSelectedItem() != null) {
            getFiberSelection();
        } else {
            fiberColor = Color.red;
            updateForm();
        }
    }//GEN-LAST:event_cbFibersPopupMenuWillBecomeInvisible

    private void cbFibersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFibersActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbFibersActionPerformed

    private void cbEpoxyPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbEpoxyPopupMenuWillBecomeInvisible
        if (cbEpoxy.getSelectedItem() != null) {
            getEpoxySelection();
        } else {
            epoxyColor = Color.white;
            updateForm();
        }
    }//GEN-LAST:event_cbEpoxyPopupMenuWillBecomeInvisible

    private void cbTypePreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTypePreActionPerformed
        soort = MaterialDirection.NULNEGENTIG;
        cbType.setSelectedIndex(2);
        if (cbTypePre.getSelectedIndex() == 0) {
            soort = MaterialDirection.UNIDIRECTIONAAL;
            cbType.setSelectedIndex(0);
        } else if (cbTypePre.getSelectedIndex() == 1) {
            soort = MaterialDirection.MINVIJFENVEERTIGVIJFENVEERTIG;
            cbType.setSelectedIndex(1);
        }
        updateForm();
    }//GEN-LAST:event_cbTypePreActionPerformed

    private void btnAddMaterialPreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddMaterialPreActionPerformed
        try {
            soort = MaterialDirection.NULNEGENTIG;
            if (cbTypePre.getSelectedIndex() == 0) {
                soort = MaterialDirection.UNIDIRECTIONAAL;
            } else if (cbTypePre.getSelectedIndex() == 1) {
                soort = MaterialDirection.MINVIJFENVEERTIGVIJFENVEERTIG;
            }
            if (txtNaamPre.getText().equalsIgnoreCase("")) {
                throw new NoNameGivenException();
            }
            System.out.println(cbTypePre.getSelectedIndex());
            double el = Double.parseDouble(txtEl.getText()) * 1e9;
            double et = Double.parseDouble(txtEt.getText()) * 1e9;
            double nult = Double.parseDouble(txtNult.getText());
            double glt = Double.parseDouble(txtGlt.getText()) * 1e9;
            double rho = Double.parseDouble(txtRho.getText());
            double dikte = Double.parseDouble(txtDiktePre.getText());
            double alpha1 = Double.parseDouble(txtAlpha1.getText());
            double alpha2 = Double.parseDouble(txtAlpha2.getText());
            //todo refactor
            // Global.data.addLamel(new Lamel(txtNaamPre.getText(), el, et, nult, glt, rho, alpha1, alpha2, dikte, new ColorSet(epoxyColor, fiberColor)));
        /*} catch (NameAlreadyExistsException ex) {
            Logger.getLogger(AddLayer.class.getName()).log(Level.SEVERE, null, ex);*/
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(rootPane, "One of the values you entered is not valid");
        } catch (NoNameGivenException ex) {
            JOptionPane.showMessageDialog(rootPane, "Please enter a name for the material");
        /*} catch (BelowOrEqualsToZeroException ex) {
            Logger.getLogger(AddLayer.class.getName()).log(Level.SEVERE, null, ex); */
        }
        if (txtNaamPre.getText().equals("Material" )){//+ Global.data.geefNieuweMaterialNaam())) {
            //todo refactor
            // Global.data.gebruikNieuweMaterialNaam();
        }
        //todo refactor
        //Global.menu.refreshScreens();
        this.dispose();
    }//GEN-LAST:event_btnAddMaterialPreActionPerformed

    private void btnFiberColorPreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFiberColorPreActionPerformed
        JColorChooser cc = new JColorChooser();
        cc.setPreviewPanel(new JPanel());
        cc.repaint();
        Color kleurtje = cc.showDialog(rootPane, "Choose a plot color", Color.red);
        if (kleurtje != null) {
            fiberColor = kleurtje;
        }
        btnFiberColor.setBackground(fiberColor);
        updateForm();
    }//GEN-LAST:event_btnFiberColorPreActionPerformed

    private void btnEpoxyColorPreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEpoxyColorPreActionPerformed
        JColorChooser cc = new JColorChooser();
        cc.setPreviewPanel(new JPanel());
        cc.repaint();
        Color kleurtje = cc.showDialog(rootPane, "Choose a plot color", Color.red);
        if (kleurtje != null) {
            epoxyColor = kleurtje;
        }
        btnEpoxyColor.setBackground(epoxyColor);
        updateForm();
    }//GEN-LAST:event_btnEpoxyColorPreActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddMaterial;
    private javax.swing.JButton btnAddMaterialPre;
    private javax.swing.JButton btnEpoxyColor;
    private javax.swing.JButton btnEpoxyColorPre;
    private javax.swing.JButton btnFiberColor;
    private javax.swing.JButton btnFiberColorPre;
    private components.SteppedComboBox cbEpoxy;
    private components.SteppedComboBox cbFibers;
    private javax.swing.JComboBox cbType;
    private javax.swing.JComboBox cbTypePre;
    private draw.pnlExample examp;
    private draw.pnlExample examp1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField txtAlpha1;
    private javax.swing.JTextField txtAlpha2;
    private javax.swing.JTextField txtDikte;
    private javax.swing.JTextField txtDiktePre;
    private javax.swing.JTextField txtEl;
    private javax.swing.JTextField txtEt;
    private javax.swing.JTextField txtFabrikant;
    private javax.swing.JTextField txtFabrikantPre;
    private javax.swing.JTextField txtGlt;
    private javax.swing.JTextField txtNaam;
    private javax.swing.JTextField txtNaamPre;
    private javax.swing.JTextField txtNult;
    private javax.swing.JTextField txtRho;
    private javax.swing.JTextField txtVf;
    // End of variables declaration//GEN-END:variables

    private void getFiberSelection() {
        if(cbFibers.getSelectedIndex()!=-1){
            f = (Fiber) cbFibers.getSelectedItem();
            fiberColor = f.getColor();
            updateForm();
        }
    }
    
    private void updateForm() {
        int selectionfibcb = cbFibers.getSelectedIndex();
        int selectionepocb = cbEpoxy.getSelectedIndex();
        cbEpoxy.removeAllItems();
        cbFibers.removeAllItems();

        /* todo refactor
        Iterator<Epoxy> epoIt = Global.data.getEpoxys();
        boolean noEpoxy = true;
        boolean noFiber = true;
        while (epoIt.hasNext()) {
            noEpoxy = false;
            cbEpoxy.addItem(epoIt.next());
        }
        Iterator<Fiber> fibIt = Global.data.getFibers();
        while (fibIt.hasNext()) {
            noFiber = false;
            cbFibers.addItem(fibIt.next());
        } */


        
        txtVf.setText(String.valueOf(vf));

        btnEpoxyColor.setBackground(epoxyColor);
        btnFiberColor.setBackground(fiberColor);
        btnEpoxyColorPre.setBackground(epoxyColor);
        btnFiberColorPre.setBackground(fiberColor);
        examp1.setSet(new ColorSet(epoxyColor, fiberColor));
        examp.setSet(new ColorSet(epoxyColor, fiberColor));
        examp.setSoort(soort);
        examp1.setSoort(soort);
        examp.repaint();
        examp1.repaint();

        /* todo refactor
        if(!noEpoxy && !noFiber)
        {
            jTabbedPane1.setEnabledAt(0, true);
            jTabbedPane1.setSelectedIndex(0);
            cbEpoxy.setSelectedIndex(selectionepocb);
            cbFibers.setSelectedIndex(selectionfibcb);
        }
        else
        {
            jTabbedPane1.setEnabledAt(0, false);
            jTabbedPane1.setSelectedIndex(1);
        } */
        this.validate();
        this.repaint();

    }

    private void getEpoxySelection() {
        if(cbEpoxy.getSelectedIndex()!=-1){
            e = (Epoxy) cbEpoxy.getSelectedItem();
            epoxyColor = e.getColor();
            updateForm();
        }
    }
}
